package com.wss.common.context.util;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author 赵飞
 * @version V1.0
 * @Title: 全局对外接口数据令牌校验接口
 * @Package com.zippo.common.util
 * @Description:
 * @date 2017/8/29
 */
public class TokenUtil {

	private static final String ASE_KEY = "~!@#$%^&*()zippo";

	/**
	 * @param token
	 * @desc 校验传输令牌是否有效
	 * @return
	 */
	public static boolean isVerifyToken(String token){

		return AESUtil.encryptHex(DateUtil.getMonday(),ASE_KEY).equals(token);
	}

	/**
	 * @param request
	 * @desc 校验传输令牌是否有效
	 * @return
	 */
	public static String getParamBody(HttpServletRequest request){
		StringBuffer stringBuffer = new StringBuffer();
		try {
			ServletInputStream in= request.getInputStream();
			BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
			String oneLine = "";
			while((oneLine = bufferedReader.readLine())!=null){
				stringBuffer.append(oneLine);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}



		return stringBuffer.toString().trim();
	}
}
